//
//  HOPStatusForwardCell.swift
//  WB01
//
//  Created by HOP on 15/12/22.
//  Copyright © 2015年 HOP. All rights reserved.
//

import UIKit

class HOPStatusForwardCell: HOPStatusesCell {

   override var status: HOPStatus? {
        didSet {
            if let forwardStatus = status?.retweeted_status {
            let text = "@\(forwardStatus.user?.screen_name): \(forwardStatus.text)"
                forwardLabel.text = text
             }
        
        }
    
    
    }
    override func prepareUI() {
    super.prepareUI()
    // 添加子控件
        contentView.addSubview(bkgButton)
        contentView.addSubview(forwardLabel)
        // 将背景按钮发送到最底部
        contentView.sendSubviewToBack(bkgButton)
        // 添加约束
        /// 背景按钮,左上角,在微博文本label的底部左边
        bkgButton.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: -8, y: 8))
         /// 背景按钮,右下角,在底部视图右上角
        bkgButton.ff_AlignVertical(type: ff_AlignType.TopRight, referView: bottomView, size: nil, offset: CGPoint.init(x: 0, y: 0))
        /// 被转发微博文本label,在背景按钮内部,左上角
        forwardLabel.ff_AlignInner(type: ff_AlignType.TopLeft, referView: bkgButton, size: nil, offset: CGPoint.init(x: 8, y: 8))
        /// 被转发微博文本label宽度
        contentView.addConstraint( NSLayoutConstraint(item: forwardLabel, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: UIScreen.mainScreen().bounds.width - 2 * 8))
        // 微博配图
        let cons = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: forwardLabel, size: CGSize(width: 290, height: 290), offset: CGPoint(x: 0, y: 8))
        // 获取微博配图视图的宽高约束
        // 注意: 设置约束的时候需要设置 size， 不然框架不会添加宽高约束,拿不到宽高约束
        pictureViewWidthCon = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Width)
        pictureViewHeightCon = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Height)
       
    }
    
      // MARK: - 懒加载
    /// 背景
    private lazy var bkgButton: UIButton = {
    let button = UIButton()
    button.backgroundColor = UIColor(white: 0.88, alpha: 1)
        return button
    }()
    /// 转发微博的文本内容
    private lazy var forwardLabel: UILabel = {
    let label = UILabel()
        label.textColor = UIColor()
        label.font = UIFont.systemFontOfSize(14)
        label.textColor = UIColor.darkGrayColor()
        label.numberOfLines = 0
        label.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.width - 2 * 8
    return label
    }()
}
